<template>
  <div class="content">
    <dt-search ref="search" :label-width="90">
      <Button type="primary" v-if="unlocking('0207050401')" @click="onExport">导出</Button>
    </dt-search>

    <dt-grid ref="table" page :onFetch="onFetch" />
  </div>
</template>

<script>
  import moment from 'moment'
  import Column from './opt/Column.js'
  import SearchOpt from './opt/SearchOpt.js'
  import financialMgr from '@/biz/report/financialReport.js'

  export default {
    data() {
      return {
        search: {
          commissionMonth: moment(new Date()).format('YYYY-MM'),
          commStartMonth: null,
          commEndMonth: null,
          bonusStartMonth: null,
          bonusEndMonth: null
        }
      }
    },
    mounted() {
      this.$refs.table.init(this, new Column())
      this.$refs.search.init(this.$refs.table, new SearchOpt(this.search), this.search)
      this.$refs.table.fetch()
    },
    methods: {
      onFetch(data) {
        this.search = data
        if (data.housesId || data.commissionMonth || data.bonusMonth) {
          return financialMgr.detailList(data)
        } else {
          let title = '案场名称，佣金单月份，奖金单月份至少输入一个'
          this.$Message.error(title)
          return Promise.reject(new Error(title))
        }
      },
      onExport() {
        financialMgr.detailExport(this.search)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    padding: 20px;
  }
</style>
